#include<iostream>
#include<cstdio>
#include<queue>
#include<string>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<stack>
#include<algorithm>
#include<vector>
#include<utility>
#include<deque>
#include<unordered_map>

#define INF 0x3f3f3f3f
#define mod 1000000007
#define endl '\n'
#define eps 1e-6

inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

inline int lowbit(int x) { return x & -x; }

inline int read() {
    int x = 0, t = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-')t = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '0') {
        x = (x << 1) + (x << 3) + c - '0';
        c = getchar();
    }
    return x * t;
}

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
const int N = 1005;
char mp[N][N];
bool vis[N][N];
int stx, sty;
int enx, eny;
int dist[N][N];
int k, n, m;

int bfs() {
    memset(vis, 0, sizeof vis);
    memset(dist, 0, sizeof dist);

    queue<PII> q;
    q.push({stx, sty});
    int dx[4] = {0, -1, 0, 1}, dy[4] = {1, 0, -1, 0};
    while (q.size()) {
        auto t = q.front();
        q.pop();
        if (t.first == enx && t.second == eny)return dist[t.first][t.second];
        for (int i = 0; i < 4; ++i) {
            int x = t.first + dx[i];
            int y = t.second + dy[i];

            if (x < 0 || x >= n || y < 0 || y >= m)continue;
            if (mp[x][y] == '#')continue;

            if (mp[x][y] == '.' && vis[x][y])continue;

            q.push({x, y});
            dist[x][y] = dist[t.first][t.second] + 1;
            vis[x][y] = true;
        }
    }
    return -1;
}

int main() {

    cin >> k >> n >> m;
    LL res = 0;
    bool tag = true;
    for (int r = 1; r <= k; ++r) {
        for (int i = 0; i < n; ++i) {
            scanf("%s", &mp[i]);
        }
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                if (mp[i][j] == 'S') {
                    stx = i;
                    sty = j;
                }
                if (mp[i][j] == 't') {
                    stx = i;
                    sty = j;
                }
                if (mp[i][j] == 'T') {
                    enx = i;
                    eny = j;
                }
                if (mp[i][j] == 'E') {
                    enx = i;
                    eny = j;
                }
            }
        }
        int t = bfs();
        if (bfs() == -1) {
            tag = false;
        } else res += t;
    }

    if (!tag)printf("Trapped Maze!!!");
    else printf("%lld\n", res);
    return 0;
}